@extends('layouts.app')
@section('title', '内容系统-分类管理')
@section('content')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header layuiadmin-card-header-auto">
                <button class="layui-btn LAY-btn-category" data-type="add">添加</button>
            </div>
            <div class="layui-card-body">
                <table id="LAY-app-content-category" lay-filter="LAY-app-content-category"></table>
                <script type="text/html" id="LAY-app-content-categorybar">
                    <a class="layui-btn layui-btn-xs" lay-event="children">子分类</a>
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        layui.use(['index', 'contlist', 'table'], function(){
            var $ = layui.$
                , admin = layui.admin
                , table = layui.table
                , form = layui.form;
            var active = {
                add: function(){
                    layer.open({
                        type: 2
                        ,title: '添加分类'
                        ,content: "/article_category/create"
                        ,area: ['500px', '450px']
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            form.on('submit(layuiadmin-app-categories-submit)', function (data) {
                                admin.req({
                                    url: "/article_category"
                                    , data: data.field
                                    , type: "post"
                                    , done: function (res) {
                                        if (res.code === 0) {
                                            layer.msg(res.msg, {icon: 6});
                                            table.reload('LAY-app-content-category');
                                            layer.close(index);
                                        } else {
                                            layer.msg(res.msg, {icon: 5});
                                        }
                                    }
                                });
                            });
                        }
                    });
                }
            }
            $('.layui-btn.LAY-btn-category').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
@endsection
